import { _decorator } from 'cc';
import { Root } from './framework/assets/core/Root';
import { oops } from './framework/assets/core/Oops';
import { smc } from './config/singletonModule';
import { InitEntity } from './init/initEntity';
import { ecs } from './framework/assets/libs/ecs/ECS';
import { uiPrefab } from "./config/config";
import { GridCheckSystem } from "./ecs/gridCheckSystem";
import { CellViewSystem } from "./ecs/cellViewSystem";
import { InitSystem } from "./init/initSystem";
import { EffectSystem } from "./ecs/effectSystem";
import { AudioSystem } from "./ecs/audioSystem";

const { ccclass } = _decorator;

// 游戏入口
@ccclass('Main')
export class Main extends Root {
    protected initGui() {
        oops.gui.init(uiPrefab);
    }

    // 更新帧
    update(dt: number) {
        oops.ecs.execute(dt);
    }

    protected initEcsSystem() {
        // 初始化系统
        oops.ecs.add(new InitSystem());
        // 格子消除系统
        oops.ecs.add(new GridCheckSystem());
        oops.ecs.add(new CellViewSystem());
        oops.ecs.add(new EffectSystem());
        oops.ecs.add(new AudioSystem());
    }

    protected run() {
        // 添加系统
        smc.initialize = ecs.getEntity<InitEntity>(InitEntity);
    }
}
